#include "contractinfodialog.h"
#include "ui_contractinfodialog.h"
#include "contractcenter.h"

ContractInfoDialog::ContractInfoDialog(ChildWindowBase *parent) :
	ChildWindowBase(parent),
    ui(new Ui::ContractInfoDialog)
{
    ui->setupUi(this);
	setupWidgets();
	connect(this, SIGNAL(accepted()), this, SLOT(onAccept()));
}

ContractInfoDialog::ContractInfoDialog(const ContractInfo &contractInfo, ChildWindowBase *parent):
		ChildWindowBase(parent),
		ui(new Ui::ContractInfoDialog),
		m_ContractInfo(contractInfo)
{
	ui->setupUi(this);
	setupWidgets();
	connect(this, SIGNAL(accepted()), this, SLOT(onAccept()));

	ui->m_ContractId->setText(QString::number(m_ContractInfo.contractId));
	ui->m_ContractDate->setDate(m_ContractInfo.contractDate);
	ui->m_Advertiser->setText(m_ContractInfo.advertiser);
	ui->m_ProgramName->setText(m_ContractInfo.programName);
	ui->m_ProgramTypeEdit->setText(m_ContractInfo.programType);
	ui->m_ProgramLength->setText(QString::number(m_ContractInfo.programLength));
	ui->m_ProgramDescrip->setPlainText(m_ContractInfo.programDescripe);
	ui->m_StartTime->setTime(m_ContractInfo.startTime);
	ui->m_EndTime->setTime(m_ContractInfo.endTime);
	ui->m_PlayDays->setText(QString::number(m_ContractInfo.playDays));
	ui->m_UnitePrice->setText(QString::number(m_ContractInfo.unitePrice));
	ui->m_PrePrice->setText(QString::number(m_ContractInfo.prePrice));
	ui->m_ActualPrice->setText(QString::number(m_ContractInfo.actualPrice));
	ui->m_AlterDescripe->setPlainText(m_ContractInfo.alterDescripe);
	ui->m_FounderName->setText(m_ContractInfo.founderName);
}

ContractInfoDialog::~ContractInfoDialog()
{
    delete ui;
}

void ContractInfoDialog::setupWidgets()
{
	ui->m_ContractDate->setDate(QDate::currentDate());

	ui->m_ContractId->setValidator(new QIntValidator(this));
	ui->m_ProgramLength->setValidator(new QIntValidator(this));
	ui->m_PlayDays->setValidator(new QIntValidator(this));
	ui->m_UnitePrice->setValidator(new QIntValidator(this));
	ui->m_PrePrice->setValidator(new QIntValidator(this));
	ui->m_ActualPrice->setValidator(new QIntValidator(this));
}

void ContractInfoDialog::onAccept()
{
	m_ContractInfo.contractId = ui->m_ContractId->text().toInt();
	m_ContractInfo.contractDate = ui->m_ContractDate->date();
	m_ContractInfo.advertiser = ui->m_Advertiser->text();
	m_ContractInfo.programName = ui->m_ProgramName->text();
	m_ContractInfo.programType = ui->m_ProgramTypeEdit->text();
	m_ContractInfo.programLength = ui->m_ProgramLength->text().toInt();
	m_ContractInfo.programDescripe = ui->m_ProgramDescrip->toPlainText();
	m_ContractInfo.startTime = ui->m_StartTime->time();
	m_ContractInfo.endTime = ui->m_EndTime->time();
	m_ContractInfo.playDays = ui->m_PlayDays->text().toInt();
	m_ContractInfo.unitePrice = ui->m_UnitePrice->text().toLong();
	m_ContractInfo.prePrice = ui->m_PrePrice->text().toLong();
	m_ContractInfo.actualPrice = ui->m_ActualPrice->text().toLong();
	m_ContractInfo.alterDescripe = ui->m_AlterDescripe->toPlainText();
	m_ContractInfo.founderName = ui->m_FounderName->text();
}

void ContractInfoDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
